package cn.gqr.service;

import cn.gqr.dao.UserDao;
import cn.gqr.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailsService implements UserDetailsService {

    @Autowired
    BCryptPasswordEncoder bcrypt;

    @Autowired
    UserDao ud;


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        System.out.println("username : " + s );
        //根据username 获取数据库的user对象
        User user = ud.findByUsername(s);
        System.out.println(user);
        return user;
    }

}
